var user = document.getElementById('user');
var pw = document.getElementById('pw');
var age = document.getElementById('age');
var yb = document.getElementById('you');
user.onchange = function(){
    if(user.value.length < 8 || user.value.length > 10)
    alert("用户名不正确！用户名长度8-10位");
}
pw.onchange = function(){
    if(pw.value.length < 6 || pw.value.length > 8)
    alert("密码不正确！密码长度6-8位");
}
    
email.onchange = function(){
    var email = this.value;
    var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
    if(!reg.test(email))
    alert("邮箱格式不正确");
}  
age.onchange = function(){
    var reg = /^(?:0|[1-9][0-9]?|100)$/;
    if(!reg.test(age.value))
    alert("年龄不正确！年龄为0-100整数");
}  
yb.onchange = function(){
    var reg = /^[0-9]{6}$/;
    if(!reg.test(yb.value))
    alert("邮编不正确！邮编为6位数字");
}
//计算平均值
function AverageScores() {
     var result = 0;
     var sum = 0;
       $(".score").each(function() {
        sum++;
             result = result + Number($(this).attr("value"));
    });
    document.getElementById("average_score").value = parseFloat(result / sum);
    document.getElementById("sum").value = sum;
}
//增添一行学生信息
function Add_information() {
    document.getElementById("Add_information").outerHTML =
        '学生姓名:<input type="text"   value="">课程成绩:<input type="text"  class="score" ><br /><div id="Add_information"></div>'
}
var yx = document.getElementById('email');
var pas = document.getElementById('pas');
var cw1 = document.getElementById('cw1');
var cw2 = document.getElementById('cw2');
yx.onblur = function(){
    if(yx.value.length < 6 || yx.value.length > 18){
        cw1.style.display = 'block';
        cw2.style.display = 'block';
    }
    else{
        cw1.style.display = 'none';
        cw2.style.display = 'none';
    }    
}
pas.onblur = function(){
    if(pas.value.length < 6 || pas.value.length > 16){
        cw3.style.display = 'block';
        cw4.style.display = 'block';
    }
    else{
        cw3.style.display = 'none';
        cw4.style.display = 'none';
    }
}
var tab_list = document.querySelector('.tab_list');
var lis = tab_list.querySelectorAll('li');
var items = document.querySelectorAll('.item');
 //for循环绑定点击事件
 for(var i = 0; i < lis.length; i++){
    lis[i].onclick = function() {
        for(var i = 0; i < lis.length; i++){
            lis[i].setAttribute('index',i);
            lis[i].className = '';
        }
        this.className = 'current';
        var index = this.getAttribute('index');
        for(var i = 0; i<items.length; i++){
            items[i].style.display = 'none';
        }
        items[index].style.display = 'block';
    }
}
 //全选
 var quan = document.querySelector('.quan');
 var fan = document.querySelector('.fan');
 var kuang = document.getElementsByName("k1");
 function quanx(){
     if(quan.checked == true){
         for(var i = 0; i < kuang.length; i++){
             kuang[i].checked = true;
         }
     }
     else{

         for(var i = 0; i < kuang.length; i++){
             kuang[i].checked = false;
         }
     }
 }
 function fanx(){
     if(fan.checked == true){
         for(var i = 0; i < kuang.length; i++){
             kuang[i].checked = ! kuang[i].checked;
         }
     }
     else{
         for(var i = 0; i < kuang.length; i++){
             kuang[i].checked = ! kuang[i].checked;
         }
     }
 }